<%-- 
    Document   : Giohang
    Created on : Dec 28, 2013, 1:15:47 AM
    Author     : Welcome
--%>

<%@page import="businesscard.DAO.GiohangDAO"%>
<%@page import="businesscard.DAO.UserDAO"%>
<%@page import="bc.entity.User"%>
<%@page import="bc.entity.Giohang"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/bocuc.css" type="text/css"/>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
        <link rel="stylesheet" href="css/trangcanhan.css" type="text/css"/>
        <link rel="stylesheet" href="css/testcss.css" type="text/css"/>
        <link rel="stylesheet" href="css/mystyle.css" type="text/css"/>
        <link rel="stylesheet" href="css/botoncss.css" type="text/css"/>
        <script type="text/javascript" src="jquery/jquery-1.1.3.1.min.js"></script> 
        <script type="text/javascript" src="jquery/jquery-1.4.2.js"></script> 
        <script type="text/javascript" src="jquery/jquery-latest.js"></script>
        <script type="text/javascript" src="jquery/myjquery.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

        <title>JSP Page</title>
         <script type="text/javascript" src="jquery/jquery-1.8.0.min.js"></script>

      
          <script type="text/javascript" >
              
            $(function() {
                $(".inputsearch").keyup(function()
                {
                    var searchid = $(this).val();
                    var dataString = 'search=' + searchid;
                    if (searchid !== '')
                    {
                        $.ajax({
                            type: "POST",
                            url: "searchAjax.jsp",
                            data: dataString,
                            cache: false,
                            success: function(html)
                            {
                                $("#showhint").html(html).show();
                            }
                        });
                    }else{
                         jQuery("#showhint").hide();
                    }
                    return false;
                });

                jQuery("#showhint").live("click", function(e) {
                    var $clicked = $(e.target);
                    var $name = $clicked.find('.name').html();
                    var decoded = $("<div/>").html($name).text();
                    $('#searchid').val(decoded);
                });
                jQuery(document).live("click", function(e) {
                    var $clicked = $(e.target);
                    if (!$clicked.hasClass("inputsearch")) {
                        jQuery("#showhint").fadeOut();
                    }
                });
                $('#searchid').click(function() {
                    jQuery("#showhint").fadeIn();
                });
                
            });
        </script>
        <style type="text/css">
         //body{ 
         //       font-family:Tahoma, Geneva, sans-serif;
         //       font-size:18px;
         //   }
        //    .content{
        //        width:900px;
        //        margin:0 auto;
        //    }
            .name{
                width:446px;
                
                margin-top:-1px !important;
                background-color:transparent !important;
                margin-left:0;}
            #showhint
            {
                position:absolute;
                width:446px;
                padding:10px;
                display:none;
                margin-top:-1px;
                border-top:0px;
                overflow:hidden;
                border:1px #CCC solid;
                background-color: white;
                margin-left: 423px;
            }
            .show
            {
                padding:10px; 
                border-bottom:1px #999 dashed;
                font-size:15px; 
                height:50px;
            }
            .show:hover
            {
                background:#4c66a4;
                color:#FFF;
                cursor:pointer;
            }
            .name:hover
            {
                background:#4c66a4;
                color:#FFF;
                cursor:pointer;
            }
        </style>
        <script>
            var xmlhttp
            function showThanhToan(str)
            {
                xmlhttp = GetXmlHttpObject();

                if (xmlhttp == null)
                {
                    alert("Your browser does not support Ajax HTTP");
                    return;
                }
                var url = "showThanhToan.jsp";
                url = url + "?id=" + str;

                xmlhttp.onreadystatechange = getOutput;
                xmlhttp.open("GET", url, true);
                xmlhttp.send(null);
            }

            function getOutput()
            {
                // if (xmlhttp.readyState==4)
                // {
                document.getElementById("txtThanhtoan").innerHTML = xmlhttp.responseText;
                //  }
            }

            function GetXmlHttpObject()
            {
                if (window.XMLHttpRequest)
                {
                    return new XMLHttpRequest();
                }
                if (window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                return null;
            }
        </script>
    </head>
    <body>
        <div class="bodypage">
            <!phan dau cua trang>
            <div class="top">
                <%@include file='header.jsp'%>
            </div>
            <!phan search>
            <div class="khoangcachtrang">
                <div class="searchgroup">

                    <%@include file='search.jsp' %> 
                    <div class="chontimkiem">
                        <a href="timkiemnangcao.jsp">Tìm Kiếm Nâng Cao</a>
                    </div>

                </div>
            </div>

            <!phan giua trang >
            <div class="centerpage">
                <div class="leftsite">
                    <div class="menuweb">
                        <%@include file='menuleft.jsp' %>
                    </div>
                </div>
                <div class="contentCanhan">
                    <div class="khoangtrang"></div>
                    <div class="GiohangPage">
                        <h1>Giỏ hàng!</h1>
                        <%
                            //Giohang gh=(Giohang)session.getAttribute("giohang");
                            //if(gh==null){
                            HttpSession session1 = request.getSession();
                            User usr = (User) session1.getAttribute("USER");
                            String username = usr.getUser();
                            UserDAO userDAO1 = new UserDAO();
                            User user5 = userDAO1.getUser2(username);
                            int id_user = user5.getIdUser();
                            GiohangDAO ghDAO = new GiohangDAO();
                            Giohang[] gh = ghDAO.getAllGiohang(id_user);
                            if (gh != null) {

                        %>
                        <div class="tabledetail">
                            <table align="center" border="1" width="500px">
                                <tr>
                                    <th>STT</th>
                                    <th>Tên liên hệ</th>
                                    <th>Đơn giá</th>
                                    <th>Xóa</th>
                                </tr>
                                <%
                                    int tongtien = 0;
                                    for (int i = 0; i < gh.length; i++) {
                                        String ten = gh[i].getLienhe().getTen();
                                        int tien = gh[i].getTongtien();
                                        tongtien += tien;
                                        
                                %>
                                <tr>
                                    <td><%=i + 1%></td>
                                    <td><%=ten%></td>                            
                                    <td><%=tien%>VND</td>        
                                <td>
                                    <form action="CartController" method="get">
                                    <input type="checkbox" value="<%=gh[i].getIdGiohang()%>" name="txtXoa"/>

                                    <%--  <a onclick="xoasp(<%= ms %>)">Xoá</a>--%>
                                </td>
                                </tr>
                                <% }%>
                                <tr>
                                    <td align="right" colspan="6" ><b>Tổng tiền:&nbsp;<%=tongtien%>VND</b></td>
                                </tr>
                            </table>  
                            
                                
                                    <input class="button" type="submit" value="Bỏ liên hệ" name="action"/>
                                    
                                </form> 
                           
                            <span id="textcart"> <a href="index.jsp"> Mua thêm liên hệ</a></span> 
                            <span id="textthanhtoan"><button id="thanhtoan" onclick="showThanhToan();">Thanh toán</button></span>
                            </table>
                        </div>
                        <div id="txtThanhtoan"></div>
                        <% }%>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
